package com.example.demo.service.impl;

import com.example.demo.config.annotation.SwitchSource;
import com.example.demo.dao.UserMapper;
import com.example.demo.domain.po.SystemUser;
import com.example.demo.domain.vo.UserLoginVO;
import com.example.demo.service.UserService;
import com.example.demo.token.generator.JwtTokenGenerator;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: 聂吉泽
 * @Description:
 * @Date: create in 2021/11/4 17:36
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private JwtTokenGenerator jwtTokenGenerator;

    JdbcTemplate jdbcTemplate;
    @Override
    public List<SystemUser> selectUsers() {
        return userMapper.selectUsers();
    }

    @Override
    public String login(UserLoginVO userLoginVO) {
        SystemUser user=new SystemUser();
        BeanUtils.copyProperties(userLoginVO,user);
        return jwtTokenGenerator.createToke(user);
    }

    @Override
    @Transactional
    public void insertUsers(String username, String password) {
        userMapper.insertUserSlave(username,password);
        userMapper.insertUserMaster(username,password);
    }

}
